#include "widget.h"
#include "ui_widget.h"
#include <QPushButton>
#include <QGridLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);

    QPushButton *btn1 = new QPushButton("按钮1");
    QPushButton *btn2 = new QPushButton("按钮2");
    QPushButton *btn3 = new QPushButton("按钮3");
    QPushButton *btn4 = new QPushButton("按钮4");

    QGridLayout *layout = new QGridLayout();
//    // 按照水平方向摆放
//    layout->addWidget(btn1, 0, 0);
//    layout->addWidget(btn2, 0, 1);
//    layout->addWidget(btn3, 0, 2);
//    layout->addWidget(btn4, 0, 3);

//    // 按照垂直方向摆放
//    layout->addWidget(btn1, 0, 0);
//    layout->addWidget(btn2, 1, 0);
//    layout->addWidget(btn3, 2, 0);
//    layout->addWidget(btn4, 3, 0);

    // 按照一排一个按钮摆放
    layout->addWidget(btn1, 0, 0);
    layout->addWidget(btn2, 1, 1);
    layout->addWidget(btn3, 2, 2);
    layout->addWidget(btn4, 3, 3);

    this->setLayout(layout);
}

Widget::~Widget()
{
    delete ui;
}

